-- LaunchAction
-- create by chendh
-- 投掷行为表现

LaunchAction = class("LaunchAction", function()
    return ActionBase.create();
end);

function LaunchAction.create(fromPos, toPos, args)
    local self = LaunchAction.new();
    self.fromPos    = fromPos;
    self.toPos      = toPos;
    self.args       = args;
    return self;
end

-- 构造函数
function LaunchAction:ctor()
end

-- 开始播放
function LaunchAction:play()
    -- 播放飞行特效
    local effectId = 0;
    local data = self.args;
    local pos = cc.p(0, 0);

    -- 如果传入了skillId那么去获取技能配置的特效，否则使用effectId
    if type(data.skill_id) == "number" then
        effectId = SkillM.query(data.skill_id, "scene_effect");
    else
        effectId = data.effect_id;
    end

    -- 如果effectId无效，那么直接返回了
    if not effectId or type(effectId) ~= "number" or effectId <= 0 then
        return 0;
    end

    -- 根据effectId创建光效
    local parentNode = UIDungeonMgr:getCurLevel():getEffectParent();
    local duration, effect = playEffect(parentNode, effectId, self.fromPos.x, self.fromPos.y);

    if effect == nil then
        return 0;
    end

    -- 如果传入持续时间，那么直接覆盖
    if data.duration then
        duration = data.duration;
    end

    -- 光效移动
    local offset    = EffectM.query(effectId, "off_set");
    local posX      = self.toPos.x + tonumber(offset[1]);
    local posY      = self.toPos.y + tonumber(offset[2]);

    local moveTo    = cc.MoveTo:create(duration, cc.p(posX, posY));
    effect:runAction(cc.Sequence:create(moveTo));

    print("LaunchAction : " .. duration);

    return duration;
end

return LaunchAction;